package com.huangmb.anymark.app.api;

import com.alibaba.fastjson.JSONObject;
import org.jsoup.Connection;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hmb
 * @version 1.0
 * @since 2016/5/20 15:13
 */
public class FileApi extends BaseApi{
    private static final String BASE_PATH = API_SERVER + "/file";
    private static final String PUT_POLICY = BASE_PATH + "/put_policy";

    private static final String QiniuServer = "http://o6mtttikw.bkt.clouddn.com/";

    public static void getPutPolicy(String key,Listener listener){
        JSONObject json = new JSONObject();
        json.put("scope","anymark:"+key);
        json.put("deadline",System.currentTimeMillis() / 1000L + 3600);//一小时时间
        json.put("returnBody","{\"name\": $(fname),\"size\": $(fsize),\"w\": $(imageInfo.width)," +
                "\"h\": $(imageInfo.height),\"hash\": $(etag)}");
        Map<String,String> params = new HashMap<>();
        params.put("policy",json.toString());
        execute(PUT_POLICY, Connection.Method.GET,params,listener);
    }
    public static String getDownloadUrl(String key){
        return  QiniuServer + key;
    }
}
